<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
<#assign base=request.contextPath  />
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>密码管理</title>
    <link rel="stylesheet" href="../frame/layui/css/layui.css">
   
    <link rel="icon" href="../frame/static/image/code.png">
    <script src="${base}/js/jquery-1.8.3.min.js"></script>
</head>
<body>
<div style="padding-top: 10px">
    <form class="layui-form" method="get" action="">
        <div class="layui-form-item">
        	<label class="layui-form-label">当前密码</label>
            <div class="layui-input-inline">
                <input type="text" name="account" class="layui-input" lay-verify="account" id="password" placeholder="当前密码" style="width: 300px;"/>
            </div>
        </div>
        <div class="layui-form-item">
        	<label class="layui-form-label">新密码</label>
            <div class="layui-input-inline">
                <input type="password" name="password" class="layui-input" lay-verify="password" id="newpassword1"  placeholder="新密码" style="width: 300px;"/>
            </div>
        </div>    
        <div class="layui-form-item">
        	<label class="layui-form-label">确认密码</label>
            <div class="layui-input-inline">
                <input type="password" name="password" class="layui-input" lay-verify="twopassword" id="newpassword2"  placeholder="确认密码" style="width: 300px;"/>
            </div>
        </div>  
        <div class="layui-form-item">
            <button type="button" class="layui-btn btn-submit layui-btn-danger" lay-submit="" lay-filter="sub"style="width: 300px; margin-left: 110px;" id="update">保存</button>
        </div>
    </form>
</div>

<script type="text/javascript" src="../frame/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['form', 'layer'], function () {

        // 操作对象
        var form = layui.form
                , layer = layui.layer
                , $ = layui.jquery;

        // 验证
        form.verify({
            account: function (value) {
                if (value == "") {
                    return "请输入当前密码";
                }
            },
            password: function (value) {
                if (value == "") {
                    return "请输入新密码";
                }
            },
            twopassword: function (value) {
                if (value == "") {
                    return "请输入确认密码";
                }
            },
        });

//        // 提交监听
//        form.on('submit(sub)', function (data) {
//            layer.msg("修改成功")
//        });

     
    })
    //键盘事件
    $("body").bind("keydown",function(e){
        // 兼容FF和IE和Opera
        var theEvent = e || window.event;
        var code=theEvent.keyCode || theEvent.which || theEvent.charCode;
        if (code==13) {
            //回车执行查询
            $("#login").click();
        }
    });
    $('#update').on('click',function () {
        var password=$("#newpassword1").val();
        var password1=$("#newpassword2").val();
        if (password==password1&&password!=null&&password!=""){   $.ajax({
            type: "POST",
            url: "${base}/password/update",
            data: {callPhone:${Session["user"].getCallPhone()}, password: $("#password").val(), newpassword1: $("#newpassword1").val()},
            success: function (data) {
                if (data) {
                    alert("点击确定将在2秒后跳转登录页面")
                    window.setTimeout("window.history.back(-1)",2000);
                } else {alert("修改失败，当前密码不正确")}
            }
        });
        }if (password!=password1 && password1!=null && password1!="")
            alert("两次密码输入不一致")

    })



</script>
</body>
</html>